package cn.hx.mall.order.service.impl;

import cn.hx.mall.order.dao.CompanyAddressDao;
import cn.hx.mall.order.entity.CompanyAddress;
import cn.hx.mall.order.service.CompanyAddressService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 公司收发货地址表(CompanyAddress)表服务实现类
 *
 * @author makejava
 * @since 2022-11-02 17:54:59
 */
@Service("companyAddressService")
public class CompanyAddressServiceImpl implements CompanyAddressService {
    @Resource
    private CompanyAddressDao companyAddressDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CompanyAddress queryById(Long id) {
        return this.companyAddressDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<CompanyAddress> queryAllByLimit(int offset, int limit) {
        return this.companyAddressDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param companyAddress 实例对象
     * @return 实例对象
     */
    @Override
    public CompanyAddress insert(CompanyAddress companyAddress) {
        this.companyAddressDao.insert(companyAddress);
        return companyAddress;
    }

    /**
     * 修改数据
     *
     * @param companyAddress 实例对象
     * @return 实例对象
     */
    @Override
    public CompanyAddress update(CompanyAddress companyAddress) {
        this.companyAddressDao.update(companyAddress);
        return this.queryById(companyAddress.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.companyAddressDao.deleteById(id) > 0;
    }
}